package io.yizoo.system.mapper;

import io.yizoo.system.entity.sys_code;
import io.yizoo.system.entity.sys_code_temp;

public class sys_codeMapperProvider {
    public String SelectSysCodeTemp(sys_code_temp sysCodeTemp) {
        String sql = "select * from sys_code_temp where 1=1";
        if (sysCodeTemp.getTable_name() != null && !sysCodeTemp.getTable_name().equals("")) {
            sql += " and table_name = #{table_name}";
        }
        return sql;
    }

    public String SelectSysCode(sys_code sysCode) {
        String sql = "select * from sys_code where 1=1";
        if (sysCode.getTable_name() != null && !sysCode.getTable_name().equals("")) {
            sql += " and table_name = #{table_name}";
        }
        if (sysCode.getYear() != null && sysCode.getYear() != 0) {
            sql += " and year = #{year}";
        }
        if (sysCode.getMonth() != null && sysCode.getMonth() != 0) {
            sql += " and month = #{month}";
        }
        if (sysCode.getDay() != null && sysCode.getDay() != 0) {
            sql += " and day = #{day}";
        }
        return sql;
    }

    public String InsertSysCode(sys_code sysCode) {
        String sql = "insert into sys_code (table_name, biz, code, year, month, day) values (#{table_name}, #{biz}, #{code}, #{year}, #{month}, #{day})";
        return sql;
    }

    public String UpdateSysCode(sys_code sysCode) {
        String sql = "update sys_code set code = #{code} where table_name = #{table_name}";
        if (sysCode.getYear() != null && sysCode.getYear() != 0) {
            sql += " and year = #{year}";
        }
        if (sysCode.getMonth() != null && sysCode.getMonth() != 0) {
            sql += " and month = #{month}";
        }
        if (sysCode.getDay() != null && sysCode.getDay() != 0) {
            sql += " and day = #{day}";
        }
        return sql;
    }
}
